<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>xiaxuchen的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="xiaxuchen的博客">
<meta property="og:url" content="http://yoursite.com/page/4/index.html">
<meta property="og:site_name" content="xiaxuchen的博客">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="xiaxuchen">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="./atom.xml" title="xiaxuchen的博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="./css/style.css">

<meta name="generator" content="Hexo 5.0.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="./" id="logo">xiaxuchen的博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="./">Home</a>
        
          <a class="main-nav-link" href="./archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="./atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-后端/Android Handler" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/%E5%90%8E%E7%AB%AF/Android%20Handler/" class="article-date">
  <time datetime="2020-08-07T15:08:02.028Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Android消息机制"><a href="#Android消息机制" class="headerlink" title="Android消息机制"></a>Android消息机制</h3><h3 id="一、-Handler"><a href="#一、-Handler" class="headerlink" title="一、 Handler"></a>一、 Handler</h3><ul>
<li><p>简介</p>
<p>进行线程的转换，比如最常用的通过Handler切换到主线程更新UI，但他的作用不仅仅是更新UI.</p>
<p>android为了保持高效且简单，使用单线程模型来处理UI,若在其他线程更新UI则会抛异常，如下ViewRootImpl中的代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (mThread != Thread.currentThread()) &#123;</span><br><span class="line">      <span class="keyword">throw</span> <span class="keyword">new</span> CalledFromWrongThreadException(</span><br><span class="line">              <span class="string">&quot;Only the original thread that created a view hierarchy can touch its views.&quot;</span>);</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建</p>
<p>在某个线程创建Handler就会去获取当前线程的Looper，若没有则会抛异常，所以需要创建Looper</p>
</li>
<li><p>使用</p>
<p>一般我们会通过post方法将一个runnable投递到Looper中执行，或者调用send方法发送消息，最终仍是在looper中执行，而post原理也是通过send进行的实现</p>
<p>send的原理</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">graph TB</span><br><span class="line">currentThread --handler.send--&gt; 消息将会入队Handler中的MessageQueue --looper获取消息--&gt; looper线程消费消息</span><br></pre></td></tr></table></figure>
</li>
<li><p>MessageQueue</p>
<p>消息队列，使用单向链表实现，用于存取消息</p>
</li>
<li><p>Looper</p>
<ul>
<li><p>使用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Looper.prepare(); &#x2F;&#x2F; 为当前线程创建一个Looper</span><br><span class="line">Handler handler &#x3D; new Handler(); &#x2F;&#x2F; 创建handler自动获取looper</span><br><span class="line">Looper.loop(); &#x2F;&#x2F; 开启looper循环</span><br><span class="line">Looper.quit(); &#x2F;&#x2F; 立即停止looper的执行</span><br><span class="line">Looper.quitSafely(); &#x2F;&#x2F; 执行完当前所有的消息后再停止</span><br></pre></td></tr></table></figure>

<p>注意,当looper退出时，使用send将返回false</p>
</li>
</ul>
</li>
<li><p>构造方法</p>
<p>Handler(CallBack)</p>
<p>可以传递一个CallBack对象给Handler，当Message中没有callback时调用，若CallBack.handleMessage返回false则会回调Handler的handleMessage方法</p>
<p>Handler(Looper)</p>
<p>可以给Handler指定Looper</p>
</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/%E5%90%8E%E7%AB%AF/Android%20Handler/" data-id="ckdkdagut000gvoutdwxc7ivj" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-工具/合并分枝注意事项" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/%E5%B7%A5%E5%85%B7/%E5%90%88%E5%B9%B6%E5%88%86%E6%9E%9D%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9/" class="article-date">
  <time datetime="2020-08-07T15:08:02.019Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="合并分枝注意事项"><a href="#合并分枝注意事项" class="headerlink" title="合并分枝注意事项"></a>合并分枝注意事项</h3><p>合并分枝的时候最好不要直接合并到自己的分枝，而是先从自己的分枝创建一个分枝去合并别的</p>
<p>分枝的更新，这样即使合并出问题只需要删除新创建的分枝即可，避免了对原分枝的破坏</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/%E5%B7%A5%E5%85%B7/%E5%90%88%E5%B9%B6%E5%88%86%E6%9E%9D%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9/" data-id="ckdkdagvh000qvout0tf6hjbg" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-ssm/ssm中dao层抽取(不完整版)" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/ssm/ssm%E4%B8%ADdao%E5%B1%82%E6%8A%BD%E5%8F%96(%E4%B8%8D%E5%AE%8C%E6%95%B4%E7%89%88)/" class="article-date">
  <time datetime="2020-08-07T15:08:01.958Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="SpringBoot中封装集成mybatis（gradle-idea"><a href="#SpringBoot中封装集成mybatis（gradle-idea" class="headerlink" title="SpringBoot中封装集成mybatis（gradle+idea)"></a>SpringBoot中封装集成mybatis（gradle+idea)</h1><h2 id="一、-主要内容"><a href="#一、-主要内容" class="headerlink" title="一、 主要内容"></a>一、 主要内容</h2><ul>
<li>mybatis的初步集成</li>
<li>通用mapper的集成</li>
<li>mybatis分页插件的集成</li>
<li>通用service的集成</li>
<li>整体的封装</li>
</ul>
<h2 id="二、开始"><a href="#二、开始" class="headerlink" title="二、开始"></a>二、开始</h2><h3 id="1-mybatis的初步集成"><a href="#1-mybatis的初步集成" class="headerlink" title="1. mybatis的初步集成"></a>1. mybatis的初步集成</h3><p>项目目录结构</p>
<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20191211005557744.png" alt="image-20191211005557744"></p>
<pre><code>- step 1 在项目的build.gradle的dependencies中添加mybatis依赖，如下（如果gradle版本太低则使用**compile**也可以）:</code></pre>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; mybatis启动器</span><br><span class="line">implementation(&quot;org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2&quot;)</span><br><span class="line">   implementation(&quot;org.springframework.boot:spring-boot-starter-web:2.1.8.RELEASE&quot;)</span><br><span class="line">   &#x2F;&#x2F; 测试</span><br><span class="line">   implementation(&quot;org.springframework.boot:spring-boot-starter-test:2.1.8.RELEASE&quot;)</span><br><span class="line">   testCompile(&quot;junit:junit:version:4.12&quot;)</span><br><span class="line">   &#x2F;&#x2F; 数据库连接池</span><br><span class="line">   runtime(&quot;mysql:mysql-connector-java:5.1.25&quot;)</span><br></pre></td></tr></table></figure>

<ul>
<li><p>step 2 在springboot的application.properties配置文件中配置如下属性:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">## 数据库连接池属性</span><br><span class="line">spring.datasource.driver-class-name&#x3D; com.mysql.jdbc.Driver</span><br><span class="line">## 下面的根据自己数据库的情况配置</span><br><span class="line">spring.datasource.url&#x3D; jdbc:mysql:&#x2F;&#x2F;localhost:3306&#x2F;exam?useUnicode&#x3D;true&amp;characterEncoding&#x3D;UTF-8&amp;zeroDateTimeBehavior&#x3D;convertToNull&amp;autoReconnect&#x3D;true</span><br><span class="line">spring.datasource.username&#x3D; root</span><br><span class="line">spring.datasource.password&#x3D; root</span><br><span class="line"></span><br><span class="line"># mybatis mapper(也就是dao层)所在的包</span><br><span class="line">mybatis.type-aliases-package&#x3D;com.xxc.test.mapper</span><br><span class="line"># mapper的xml映射文件的位置，一般放在resources文件夹下的mapper文件夹以xxxMapper.xml格式进行命名</span><br><span class="line">mybatis.mapper-locations&#x3D;classpath*:mapper&#x2F;*Mapper.xml</span><br></pre></td></tr></table></figure>
</li>
<li><p>step 3 在application启动类上添加MapperScan注解</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 其中的参数是mapper的包名</span><br><span class="line">@MapperScan(&quot;com.xxc.test.mapper&quot;)</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>step 4 编写实体类</p>
<p><strong>Manager.java</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">package com.xxc.test.entity;</span><br><span class="line"></span><br><span class="line">import java.math.BigInteger;</span><br><span class="line"></span><br><span class="line">public class Manager &#123;</span><br><span class="line"></span><br><span class="line">    private BigInteger id;</span><br><span class="line"></span><br><span class="line">    private String email;</span><br><span class="line"></span><br><span class="line">    private String password;</span><br><span class="line">    </span><br><span class="line">    &#x2F;&#x2F;省略get、set、toString</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</li>
<li><p>step 5 编写mapper接口以及xml映射文件</p>
<p><strong>ManagerMapper.java</strong></p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">package com.xxc.test.mapper;</span><br><span class="line"></span><br><span class="line">import com.xxc.test.entity.Manager;</span><br><span class="line">import org.springframework.stereotype.Repository;</span><br><span class="line"></span><br><span class="line">import java.util.List;</span><br><span class="line">@Repository</span><br><span class="line">public interface ManagerMapper &#123;</span><br><span class="line"></span><br><span class="line">    List&lt;Manager&gt; selectAll();</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>ManagerMapper.xml</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE mapper PUBLIC &quot;-&#x2F;&#x2F;mybatis.org&#x2F;&#x2F;DTD Mapper 3.0&#x2F;&#x2F;EN&quot;</span><br><span class="line">        &quot;http:&#x2F;&#x2F;mybatis.org&#x2F;dtd&#x2F;mybatis-3-mapper.dtd&quot;&gt;</span><br><span class="line">&lt;!--注意命名空间要与ManagerMapper接口的权限定名相同--&gt;</span><br><span class="line">&lt;mapper namespace&#x3D;&quot;com.xxc.test.mapper.ManagerMapper&quot;&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;selectAll&quot; resultType&#x3D;&quot;com.xxc.test.entity.Manager&quot; &gt;</span><br><span class="line">        SELECT * FROM manager</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">&lt;&#x2F;mapper&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>step 4 测试</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">package com.xxc.test.mapper;</span><br><span class="line"></span><br><span class="line">import org.junit.Test;</span><br><span class="line">import org.junit.runner.RunWith;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.boot.test.context.SpringBootTest;</span><br><span class="line">import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@RunWith(SpringJUnit4ClassRunner.class)</span><br><span class="line">@SpringBootTest</span><br><span class="line">public class ManagerMapperTest &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    @Autowired</span><br><span class="line">    private ManagerMapper managerMapper;</span><br><span class="line"></span><br><span class="line">    @Test</span><br><span class="line">    public void testSelectAll()&#123;</span><br><span class="line">        System.out.println(managerMapper.selectAll());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20191211004320353.png" alt="image-20191211004320353"></p>
<p>好了，springboot集成mybatis就完成了</p>
<h3 id="2-通用mapper的集成"><a href="#2-通用mapper的集成" class="headerlink" title="2.通用mapper的集成"></a>2.通用mapper的集成</h3><h4 id="1-概述"><a href="#1-概述" class="headerlink" title="1. 概述"></a>1. 概述</h4><p>由于<strong>单表</strong>的增删改查完全是模板代码，手写起来还是比较麻烦，我们可以使用通过mapper来帮我们实现，集成后我们只需要用我们的mapper接口集成CrudMapper接口即可使用，无需编写映射文件</p>
<h4 id="2-集成"><a href="#2-集成" class="headerlink" title="2. 集成"></a>2. 集成</h4><ul>
<li>step 1 在依赖中添加mapper的依赖</li>
</ul>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">implementation(<span class="string">&quot;tk.mybatis:mapper:3.4.0&quot;</span>)</span><br></pre></td></tr></table></figure>

<ul>
<li>step 2 配置（<strong>tk.mybatis.spring.mapper.MapperScannerConfigurer</strong>）</li>
</ul>
<p><strong>MyBatisConfig.java</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">package com.xxc.test.config;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;</span><br><span class="line">import org.springframework.boot.autoconfigure.AutoConfigureAfter;</span><br><span class="line">import org.springframework.context.annotation.Bean;</span><br><span class="line">import org.springframework.context.annotation.Configuration;</span><br><span class="line">import tk.mybatis.spring.mapper.MapperScannerConfigurer;</span><br><span class="line"></span><br><span class="line">import java.util.Properties;</span><br><span class="line"></span><br><span class="line">@Configuration</span><br><span class="line">@AutoConfigureAfter(MybatisAutoConfiguration.class)</span><br><span class="line">public class MyBatisConfig&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    public MapperScannerConfigurer mapperScannerConfigurer()  &#123;</span><br><span class="line">        MapperScannerConfigurer mapperScannerConfigurer &#x3D; new MapperScannerConfigurer();</span><br><span class="line">        mapperScannerConfigurer.setSqlSessionFactoryBeanName(&quot;sqlSessionFactory&quot;);</span><br><span class="line">        &#x2F;&#x2F; 这里是你的mapper的包名</span><br><span class="line">        mapperScannerConfigurer.setBasePackage(&quot;com.xxc.test.mapper&quot;);</span><br><span class="line">        Properties properties &#x3D; new  Properties();</span><br><span class="line">        properties.setProperty(&quot;notEmpty&quot;, &quot;false&quot;);</span><br><span class="line">        properties.setProperty(&quot;IDENTITY&quot;, &quot;MYSQL&quot;);</span><br><span class="line">        properties.setProperty(&quot;ORDER&quot;, &quot;BEFORE&quot;);</span><br><span class="line">        mapperScannerConfigurer.setProperties(properties);</span><br><span class="line">        return mapperScannerConfigurer;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<ul>
<li><p>step 3 修改实体类</p>
<p><strong>Manager2.java</strong></p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.xxc.test.entity;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.persistence.*;</span><br><span class="line"><span class="keyword">import</span> java.math.BigInteger;</span><br><span class="line"><span class="keyword">import</span> java.sql.Timestamp;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Table(name = &quot;manager&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Manager2</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 一定要给注解加上Id注解进行标识</span></span><br><span class="line">    <span class="meta">@Id</span></span><br><span class="line">    <span class="comment">// 主键生成策略</span></span><br><span class="line">    <span class="meta">@GeneratedValue(generator = &quot;JDBC&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> BigInteger id;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String email;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String password;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//当属性名与类名不同时使用该注解关联</span></span><br><span class="line">    <span class="meta">@Column(name = &quot;gmt_create&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> Timestamp gmtCreate;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 当属性没有与数据库的对应关系时，则使用该注解使其忽略</span></span><br><span class="line">    <span class="meta">@Transient</span></span><br><span class="line">    <span class="keyword">private</span> Manager useless;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<ul>
<li><p>step 4 修改mapper接口</p>
<p><strong>ManagerMapper2.java</strong></p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.xxc.test.mapper;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.xxc.test.entity.Manager2;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Repository;</span><br><span class="line"><span class="keyword">import</span> tk.mybatis.mapper.common.base.select.SelectAllMapper;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Repository</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">ManagerMapper2</span> <span class="keyword">extends</span> <span class="title">SelectAllMapper</span>&lt;<span class="title">Manager2</span>&gt; </span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<ul>
<li>step 5 测试</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.xxc.test.mapper;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"><span class="keyword">import</span> org.junit.runner.RunWith;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.test.context.SpringBootTest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.test.context.junit4.SpringJUnit4ClassRunner;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@RunWith(SpringJUnit4ClassRunner.class)</span></span><br><span class="line"><span class="meta">@SpringBootTest</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ManagerMapper2Test</span> </span>&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> ManagerMapper2 managerMapper2;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testSelectAll</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(managerMapper2.selectAll());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20191211011316372.png" alt="image-20191211011316372"></p>
<p>通用mapper到此就结束了？还没，虽然mapper提供了很多功能实现的接口给我们，但是一个个继承有些麻烦，我们可以封装一个CrudMapper接口，使得我们直接继承该接口就可以有增删改查的方法</p>
<h4 id="CrudMapper接口封装"><a href="#CrudMapper接口封装" class="headerlink" title="CrudMapper接口封装"></a>CrudMapper接口封装</h4><p>代码如下:</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/ssm/ssm%E4%B8%ADdao%E5%B1%82%E6%8A%BD%E5%8F%96(%E4%B8%8D%E5%AE%8C%E6%95%B4%E7%89%88)/" data-id="ckdkdagtw0007vout9rw8fk1j" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-ssm/springmvc文件的上传下载" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/ssm/springmvc%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD/" class="article-date">
  <time datetime="2020-08-07T15:08:01.929Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="springmvc文件的上传下载"><a href="#springmvc文件的上传下载" class="headerlink" title="springmvc文件的上传下载"></a>springmvc文件的上传下载</h1><h2 id="基础知识"><a href="#基础知识" class="headerlink" title="基础知识"></a>基础知识</h2><p>获取resources目录下的文件，如<img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20191207222644153.png" alt="image-20191207222644153"></p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">val</span> filename = <span class="string">&quot;知题网-试题模版.xls&quot;</span></span><br><span class="line"><span class="keyword">val</span> cpr = ClassPathResource(<span class="string">&quot;excel&quot;</span> + File.separator + filename)</span><br></pre></td></tr></table></figure>

<p>浏览器弹出下载文件框</p>
<blockquote>
<p>Content-disposition 是 MIME 协议的扩展，MIME 协议指示 MIME 用户代理如何显示附加的文件。Content-disposition其实可以控制用户请求所得的内容存为一个文件的时候提供一个默认的文件名，文件直接在浏览器上显示或者在访问时弹出文件下载对话框。<br> <strong>格式说明：</strong> content-disposition = “Content-Disposition” “:” disposition-type *( “;” disposition-parm ) 　</p>
</blockquote>
<p>解决文件名中文乱码问题</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> filenameEncoder: String</span><br><span class="line">    <span class="keyword">when</span> &#123;</span><br><span class="line">        agent.contains(<span class="string">&quot;MSIE&quot;</span>) -&gt; &#123;</span><br><span class="line">            <span class="comment">// IE浏览器</span></span><br><span class="line">            filenameEncoder = URLEncoder.encode(filename, <span class="string">&quot;utf-8&quot;</span>)</span><br><span class="line">            filenameEncoder = filenameEncoder.replace(<span class="string">&quot;+&quot;</span>, <span class="string">&quot; &quot;</span>)</span><br><span class="line">        &#125;</span><br><span class="line">        agent.contains(<span class="string">&quot;Firefox&quot;</span>) -&gt; &#123;</span><br><span class="line">            <span class="comment">// 火狐浏览器</span></span><br><span class="line">            <span class="keyword">val</span> base64Encoder = BASE64Encoder()</span><br><span class="line">            filenameEncoder = <span class="string">&quot;=?utf-8?B?&quot;</span> + base64Encoder.encode(filename.toByteArray(Charset.forName(<span class="string">&quot;utf-8&quot;</span>))) + <span class="string">&quot;?=&quot;</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> -&gt; <span class="comment">// 其它浏览器</span></span><br><span class="line">            filenameEncoder = URLEncoder.encode(filename, <span class="string">&quot;utf-8&quot;</span>)</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>



<h2 id="下载文件"><a href="#下载文件" class="headerlink" title="下载文件"></a>下载文件</h2><p>响应ResponseEntity实现下载文件:</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping(<span class="meta-string">&quot;/questions/template&quot;</span>)</span></span><br><span class="line">  <span class="function"><span class="keyword">fun</span> <span class="title">download</span><span class="params">(<span class="meta">@RequestHeader(<span class="meta-string">&quot;User-Agent&quot;</span>)</span> agent:<span class="type">String</span>)</span></span>: ResponseEntity&lt;ByteArray&gt; &#123;</span><br><span class="line">      <span class="comment">// 获取目录下的资源</span></span><br><span class="line">      <span class="keyword">val</span> filename = <span class="string">&quot;知题网-试题模版.xls&quot;</span></span><br><span class="line">      <span class="keyword">val</span> cpr = ClassPathResource(<span class="string">&quot;excel&quot;</span> + File.separator + filename)</span><br><span class="line">      <span class="comment">// 获得请求头中的User-Agent</span></span><br><span class="line">      <span class="comment">// 根据不同的客户端进行不同的编码</span></span><br><span class="line">      <span class="keyword">var</span> filenameEncoder: String</span><br><span class="line">      <span class="keyword">when</span> &#123;</span><br><span class="line">          agent.contains(<span class="string">&quot;MSIE&quot;</span>) -&gt; &#123;</span><br><span class="line">              <span class="comment">// IE浏览器</span></span><br><span class="line">              filenameEncoder = URLEncoder.encode(filename, <span class="string">&quot;utf-8&quot;</span>)</span><br><span class="line">              filenameEncoder = filenameEncoder.replace(<span class="string">&quot;+&quot;</span>, <span class="string">&quot; &quot;</span>)</span><br><span class="line">          &#125;</span><br><span class="line">          agent.contains(<span class="string">&quot;Firefox&quot;</span>) -&gt; &#123;</span><br><span class="line">              <span class="comment">// 火狐浏览器</span></span><br><span class="line">              <span class="keyword">val</span> base64Encoder = BASE64Encoder()</span><br><span class="line">              filenameEncoder = <span class="string">&quot;=?utf-8?B?&quot;</span> + base64Encoder.encode(filename.toByteArray(Charset.forName(<span class="string">&quot;utf-8&quot;</span>))) + <span class="string">&quot;?=&quot;</span></span><br><span class="line">          &#125;</span><br><span class="line">          <span class="keyword">else</span> -&gt; <span class="comment">// 其它浏览器</span></span><br><span class="line">              filenameEncoder = URLEncoder.encode(filename, <span class="string">&quot;utf-8&quot;</span>)</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="comment">// 模板代码，装配ResponseEntity</span></span><br><span class="line">      <span class="keyword">val</span> input = cpr.inputStream</span><br><span class="line">      <span class="keyword">val</span> body: ByteArray = ByteArray(input.available())</span><br><span class="line">      input.read(body)</span><br><span class="line">      <span class="keyword">val</span> headers = HttpHeaders()</span><br><span class="line">      <span class="comment">// 让浏览器显示下载文件对话框</span></span><br><span class="line">      headers.add(<span class="string">&quot;Content-Disposition&quot;</span>, <span class="string">&quot;attchement;filename=<span class="variable">$filenameEncoder</span>&quot;</span>)</span><br><span class="line">      <span class="keyword">val</span> statusCode = HttpStatus.OK</span><br><span class="line">      <span class="keyword">return</span> ResponseEntity(body, headers, statusCode)</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/ssm/springmvc%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD/" data-id="ckdkdagts0006vout0zg312e7" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-android/Window的使用" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/android/Window%E7%9A%84%E4%BD%BF%E7%94%A8/" class="article-date">
  <time datetime="2020-08-07T15:08:01.350Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>[toc]</p>
<p>Android学习笔记</p>
<h3 id="Window的使用"><a href="#Window的使用" class="headerlink" title="Window的使用"></a>Window的使用</h3><h4 id="获取"><a href="#获取" class="headerlink" title="获取"></a>获取</h4><p>在Dialog或者Activity中可以直接获取到Window对象</p>
<h4 id="核心"><a href="#核心" class="headerlink" title="核心"></a>核心</h4><ul>
<li><p>主要是对View进行操作，添加、删除、更新View到对应的window</p>
</li>
<li><p>使用Window添加或者更新view需要传入对应的LayoutParams</p>
<p>其中两个属性需要注意：</p>
<ol>
<li><p><strong>type</strong> window的类型，可以是系统Window、子window和应用window</p>
</li>
<li><p><strong>flags</strong> window的标识，用来决定View的特性，有FLAG_NOT_FOCUSABLE window不需要获取焦点输入</p>
<p>FLAG_NOT_TOUCH_MODAL window外部的区域的事件交由下层处理</p>
<p>FLAG_SHOW_WHEN_LOCKED window可以在锁屏界面显示</p>
</li>
</ol>
</li>
</ul>
<h4 id="个人理解"><a href="#个人理解" class="headerlink" title="个人理解"></a>个人理解</h4><ul>
<li>使用WindowManager#addView方法相当于添加 window</li>
<li>window实质就是ViewRootImpl</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/android/Window%E7%9A%84%E4%BD%BF%E7%94%A8/" data-id="ckdkdagtn0003vout7k0694ad" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-android/WebView的bug" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/android/WebView%E7%9A%84bug/" class="article-date">
  <time datetime="2020-08-07T15:08:01.347Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="WebView的bug"><a href="#WebView的bug" class="headerlink" title="WebView的bug"></a>WebView的bug</h1><h3 id="错误一-Binary-XML-file-line-18-Error-inflating-class-android-webkit-WebView"><a href="#错误一-Binary-XML-file-line-18-Error-inflating-class-android-webkit-WebView" class="headerlink" title="错误一:Binary XML file line #18: Error inflating class android.webkit.WebView"></a>错误一:Binary XML file line #18: Error inflating class android.webkit.WebView</h3><p>系统有问题，没有android system webview</p>
<h3 id="Android-ERR-CLEARTEXT-NOT-PERMITTED"><a href="#Android-ERR-CLEARTEXT-NOT-PERMITTED" class="headerlink" title="Android   ERR_CLEARTEXT_NOT_PERMITTED"></a>Android   ERR_CLEARTEXT_NOT_PERMITTED</h3><p>在Android 的mainfest.xml中的application添加一句配置</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">manifest</span> <span class="attr">...</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">uses-permission</span> <span class="attr">android:name</span>=<span class="string">&quot;android.permission.INTERNET&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">application</span></span></span><br><span class="line"><span class="tag">        <span class="attr">...</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:usesCleartextTraffic</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">...</span>&gt;</span></span><br><span class="line">        ...</span><br><span class="line">    <span class="tag">&lt;/<span class="name">application</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">manifest</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/android/WebView%E7%9A%84bug/" data-id="ckdkdagto0004vout1nedgt3m" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-android/IPC机制" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/android/IPC%E6%9C%BA%E5%88%B6/" class="article-date">
  <time datetime="2020-08-07T15:08:01.328Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="IPC机制"><a href="#IPC机制" class="headerlink" title="IPC机制"></a>IPC机制</h2><h3 id="一、概念"><a href="#一、概念" class="headerlink" title="一、概念"></a>一、概念</h3><p>​    android IPC意为进程间的通信，指两个进程之间的通信</p>
<h3 id="二、多进程"><a href="#二、多进程" class="headerlink" title="二、多进程"></a>二、多进程</h3><h4 id="2-1-android中开启多线程模式"><a href="#2-1-android中开启多线程模式" class="headerlink" title="2.1 android中开启多线程模式"></a>2.1 android中开启多线程模式</h4><p>只需在AndroidManifest.xml中给activity配置process属性即可运行在不同的进程中，默认是包名</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">application</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:allowBackup</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:icon</span>=<span class="string">&quot;@mipmap/ic_launcher&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:label</span>=<span class="string">&quot;@string/app_name&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:roundIcon</span>=<span class="string">&quot;@mipmap/ic_launcher_round&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:supportsRtl</span>=<span class="string">&quot;true&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:name</span>=<span class="string">&quot;.application.MyApplication&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:theme</span>=<span class="string">&quot;@style/AppTheme&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">activity</span> <span class="attr">android:name</span>=<span class="string">&quot;.MainActivity&quot;</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">intent-filter</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">action</span> <span class="attr">android:name</span>=<span class="string">&quot;android.intent.action.MAIN&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">                <span class="tag">&lt;<span class="name">category</span> <span class="attr">android:name</span>=<span class="string">&quot;android.intent.category.LAUNCHER&quot;</span> /&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">intent-filter</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">activity</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">activity</span> <span class="attr">android:name</span>=<span class="string">&quot;.SecondaryActivity&quot;</span> <span class="attr">android:process</span>=<span class="string">&quot;:remote&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">activity</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">application</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>以上配置中配置了自定义的application，让其在create的时候打印日志，初始日志打印了两次，说明applicaiton创建了两次如下是输出结果:</p>
<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20200119185909215.png" alt="image-20200119185909215"></p>
<p>进程名以:开头的话会以默认进程名为前缀，如上图就是com.cxyz.ipc:remote,其属于当前进程的子进程，而进程名不以:开头的进程可以通过ShareUID方式和它跑在一个进程中</p>
<h4 id="2-2多进程的运行方式"><a href="#2-2多进程的运行方式" class="headerlink" title="2.2多进程的运行方式"></a>2.2多进程的运行方式</h4><p>将会造成如下问题:</p>
<ol>
<li>静态成员和单例模式完全失效</li>
<li>线程同步机制失效</li>
<li>SharedPreference可靠性降低</li>
<li>Application会多次创建</li>
<li>运行在不同进程的四大组件通过内存共享数据将会失败，因为他们不在.一块内存</li>
</ol>
<h3 id="三、IPC"><a href="#三、IPC" class="headerlink" title="三、IPC"></a>三、IPC</h3><ol>
<li><p>Serializable 接口</p>
<p>java提供的一个序列化接口，对对象提供标准的序列化和反序列化操作，<strong>注意要提供SerializableId</strong>,但是系统的开销大，不适合android平台</p>
</li>
<li><p>parcelable 接口</p>
<p>Android提供的序列化方式，相比于Serializable 接口使用较复杂一点，但在android上推荐使用，类实现此接口后即可通过Intent和bundle进行传输，用法省略，Android Studio可以自动生成</p>
</li>
<li><p>Binder</p>
</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/android/IPC%E6%9C%BA%E5%88%B6/" data-id="ckdkdagtl0002vout8hnx7jtp" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-android/android笔记" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/android/android%E7%AC%94%E8%AE%B0/" class="article-date">
  <time datetime="2020-08-07T15:08:01.309Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="android笔记"><a href="#android笔记" class="headerlink" title="android笔记"></a>android笔记</h1><h2 id="命名规则"><a href="#命名规则" class="headerlink" title="命名规则"></a>命名规则</h2><p>控件id：模块名称+控件名称缩写+业务逻辑 驼峰命名法</p>
<h2 id="框架集成"><a href="#框架集成" class="headerlink" title="框架集成"></a>框架集成</h2><h3 id="一、ARouter"><a href="#一、ARouter" class="headerlink" title="一、ARouter"></a>一、ARouter</h3><ol>
<li>依赖</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">compile <span class="string">&quot;com.alibaba:arouter-api:$&#123;dep.routerVersion&#125;&quot;</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li><p>注解处理器配置</p>
<ul>
<li>java</li>
</ul>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">android &#123;</span><br><span class="line">    defaultConfig &#123;</span><br><span class="line">        javaCompileOptions &#123;</span><br><span class="line">                annotationProcessorOptions &#123;</span><br><span class="line">                    arguments = [<span class="attr">AROUTER_MODULE_NAME:</span> project.getName()]</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">dependencies &#123;</span><br><span class="line">    annotationProcessor <span class="string">&quot;com.alibaba:arouter-compiler:$&#123;dep.routerAnnotationProcessor&#125;&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>









</li>
</ol>
<ul>
<li><p>kotlin(使用kapt)</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">apply <span class="attr">plugin:</span> <span class="string">&#x27;kotlin-kapt&#x27;</span></span><br><span class="line">android &#123;</span><br><span class="line">    defaultConfig &#123;</span><br><span class="line">           kapt &#123;</span><br><span class="line">            arguments &#123;</span><br><span class="line">                arg(<span class="string">&quot;moduleName&quot;</span>, project.getName())</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">dependencies &#123;</span><br><span class="line">    kapt <span class="string">&quot;com.alibaba:arouter-compiler:$&#123;dep.routerAnnotationProcessor&#125;&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ul>
<h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><h3 id="解决recycleview子布局不能填充父容器"><a href="#解决recycleview子布局不能填充父容器" class="headerlink" title="解决recycleview子布局不能填充父容器"></a>解决recycleview子布局不能填充父容器</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> ViewHolder <span class="title">onCreateViewHolder</span><span class="params">(<span class="meta">@NonNull</span> ViewGroup parent, <span class="keyword">int</span> viewType)</span> </span>&#123;</span><br><span class="line">       View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_group_list, parent, <span class="keyword">false</span>);<span class="comment">//解决宽度不能铺满</span></span><br><span class="line">       ViewHolder holder = <span class="keyword">new</span> ViewHolder(view);</span><br><span class="line">       <span class="keyword">return</span> holder;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<h3 id="git代码写错分枝解决办法"><a href="#git代码写错分枝解决办法" class="headerlink" title="git代码写错分枝解决办法"></a>git代码写错分枝解决办法</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#第一步，将修改的代码暂存到stash</span><br><span class="line">git stash</span><br><span class="line"></span><br><span class="line">#第二步，切换到正确的分支</span><br><span class="line">git checkout targetbranch </span><br><span class="line"></span><br><span class="line">#第三步，从stash中取出暂存的代码修改。</span><br><span class="line">git stash pop</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/android/android%E7%AC%94%E8%AE%B0/" data-id="ckdkdagtq0005vout1dpygkwg" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-android/Android沉浸式状态栏" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/android/Android%E6%B2%89%E6%B5%B8%E5%BC%8F%E7%8A%B6%E6%80%81%E6%A0%8F/" class="article-date">
  <time datetime="2020-08-07T15:08:01.254Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Android沉浸式状态栏"><a href="#Android沉浸式状态栏" class="headerlink" title="Android沉浸式状态栏"></a>Android沉浸式状态栏</h2><h3 id="一、沉浸式状态栏是什么？"><a href="#一、沉浸式状态栏是什么？" class="headerlink" title="一、沉浸式状态栏是什么？"></a>一、沉浸式状态栏是什么？</h3><p>沉浸式状态栏是让状态栏的颜色透明，若有需要可以使状态栏的颜色与顶栏相同</p>
<h3 id="二、如何实现？"><a href="#二、如何实现？" class="headerlink" title="二、如何实现？"></a>二、如何实现？</h3><ol>
<li><p>android4.4版本</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) &#123;</span><br><span class="line">    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果如下:</p>
<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20200112221655851.png" alt="image-20200112221655851"></p>
</li>
<li><p>android5+版本</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) &#123;</span><br><span class="line">    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);</span><br><span class="line">    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN</span><br><span class="line">            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);</span><br><span class="line">    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);</span><br><span class="line">    window.setStatusBarColor(Color.TRANSPARENT);</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果如下:</p>
</li>
</ol>
<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20200112221748068.png" alt="image-20200112221748068"></p>
<ol start="3">
<li>6.0后设置状态栏文字颜色</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><p>使用QMUI时如何做？</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//这里同时设置了状态栏文字颜色</span></span><br><span class="line">QMUIStatusBarHelper.setStatusBarLightMode(<span class="keyword">this</span>)</span><br><span class="line">   </span><br><span class="line"><span class="comment">// styles.xml</span></span><br><span class="line">       &lt;!-- Base application theme. --&gt;</span><br><span class="line">   &lt;style name=<span class="string">&quot;AppTheme&quot;</span> parent=<span class="string">&quot;QMUI.NoActionBar&quot;</span>&gt;</span><br><span class="line">       &lt;!-- Customize your theme here. --&gt;</span><br><span class="line">       &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;</span><br><span class="line">       &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;</span><br><span class="line">       &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;</span><br><span class="line">       <span class="comment">//这里让状态栏有颜色</span></span><br><span class="line">       &lt;item name=&quot;android:fitsSystemWindows&quot;&gt;true&lt;/item&gt;</span><br><span class="line">   &lt;/style&gt;</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>如果需要让状态栏变颜色，可以设置fitSystemWindows属性给theme或者布局的root view</li>
</ol>
</li>
</ol>
<h3 id="三、参考"><a href="#三、参考" class="headerlink" title="三、参考"></a>三、参考</h3><p><a target="_blank" rel="noopener" href="https://juejin.im/post/5a25f6146fb9a0452405ad5b">掘金文章</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/android/Android%E6%B2%89%E6%B5%B8%E5%BC%8F%E7%8A%B6%E6%80%81%E6%A0%8F/" data-id="ckdkdagth0001voutew154fpm" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-android/Activity生命周期探索" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="./2020/08/07/android/Activity%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%8E%A2%E7%B4%A2/" class="article-date">
  <time datetime="2020-08-07T15:08:01.235Z" itemprop="datePublished">2020-08-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Activity生命周期探索"><a href="#Activity生命周期探索" class="headerlink" title="Activity生命周期探索"></a>Activity生命周期探索</h3><p><img src="https://img-blog.csdn.net/2018062722203023?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW5neHVlY2hhb18=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="img"></p>
<h3 id="一、正常情况下的生命周期"><a href="#一、正常情况下的生命周期" class="headerlink" title="一、正常情况下的生命周期"></a>一、正常情况下的生命周期</h3><h4 id="1-各方法的说明"><a href="#1-各方法的说明" class="headerlink" title="1. 各方法的说明"></a>1. 各方法的说明</h4><table>
<thead>
<tr>
<th align="center">生命周期方法</th>
<th align="center">是否可见</th>
<th align="center">用户可见</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">onCreate</td>
<td align="center">否</td>
<td align="center">否</td>
<td align="center">表示Activity正在创建，可以做一些初始化的工作</td>
</tr>
<tr>
<td align="center">onRestart</td>
<td align="center">是</td>
<td align="center">否</td>
<td align="center">当Activity从不可见变为可见即调用，如创建新的Activity又返回、回到桌面又返回页面</td>
</tr>
<tr>
<td align="center">onStart</td>
<td align="center">是</td>
<td align="center">否</td>
<td align="center">表示Activity已经被启动了，Activity已经可见，但未出现在前台</td>
</tr>
<tr>
<td align="center">onResume</td>
<td align="center">是</td>
<td align="center">是</td>
<td align="center">此时Activity已出现在前台了</td>
</tr>
<tr>
<td align="center">onPause</td>
<td align="center">是</td>
<td align="center">否</td>
<td align="center">表示Activity正在停止，紧接着onStop会被调用，可以做一些存储数据、停止动画的工作</td>
</tr>
<tr>
<td align="center">onStop</td>
<td align="center">否</td>
<td align="center">否</td>
<td align="center">表示Activity即将停止，可以做一些较为重量级的回收工作，但不能太耗时</td>
</tr>
<tr>
<td align="center">onDestory</td>
<td align="center">否</td>
<td align="center">否</td>
<td align="center">表示Activity即将被销毁，可以做最终的资源回收</td>
</tr>
</tbody></table>
<h4 id="2-附加说明-了解即可"><a href="#2-附加说明-了解即可" class="headerlink" title="2. 附加说明(了解即可)"></a>2. 附加说明(了解即可)</h4><ol>
<li><p>第一次启动一个activity</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">graph LR</span><br><span class="line">   onCreate --&gt; onStart --&gt; onResume</span><br></pre></td></tr></table></figure>



</li>
</ol>
<ol start="2">
<li><p>打开activity然后切换回桌面：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">graph LR</span><br><span class="line">onPause --&gt; condition&#123;Activity是否采用了透明主题&#125; -- NO --&gt; onStop</span><br></pre></td></tr></table></figure>
</li>
<li><p>当再次回到Activity时回调:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">graph LR </span><br><span class="line">onRestart --&gt; onStart --&gt; onResume</span><br></pre></td></tr></table></figure>



</li>
</ol>
<ol start="4">
<li><p>当用户按下back</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">graph LR</span><br><span class="line">onPause --&gt; onStop --&gt; onDestroy</span><br></pre></td></tr></table></figure>



</li>
</ol>
<ol start="5">
<li>当Activity被销毁再次打开生命周期和第1点一样，只是生命周期</li>
<li>onCreate和onDestory是配对的，标识创建和销毁，onStart和onStop是配对的，标识Activity是否可见，随着设备的点亮和熄灭会多次触发，onResume和onPause是配对的，标识Activity是否在前台</li>
</ol>
<h4 id="3-问题"><a href="#3-问题" class="headerlink" title="3.问题"></a>3.问题</h4><ol>
<li><p>onResume和onPause一对方法与onStart和onStop非常相像，对我们来说有什么实质性的不同呢?</p>
<p>onResume和onPause是从用户是否可见方面回调，而后者是从Activity是否可见方面回调，意义不同</p>
</li>
<li><p>假设当前Activity A打开了一个新Activity B，那么B的onResume和A的onPause哪个先执行呢？</p>
<p>由源码看出Activity是先执行onPause然后在执行新的Activity的生命周期的</p>
</li>
</ol>
<h3 id="二、异常情况下的生命周期"><a href="#二、异常情况下的生命周期" class="headerlink" title="二、异常情况下的生命周期"></a>二、异常情况下的生命周期</h3><h4 id="1-系统状态改变"><a href="#1-系统状态改变" class="headerlink" title="1. 系统状态改变"></a>1. 系统状态改变</h4><p>当系统状态改变时会导致Activity的重新创建，如横竖屏的切换，当然我们可以阻止此行为</p>
<h4 id="2-系统资源不足"><a href="#2-系统资源不足" class="headerlink" title="2.系统资源不足"></a>2.系统资源不足</h4><p>​    当系统资源不足时，将会挑选优先级较低的Activity杀死释放资源</p>
<p>​    </p>
<p>​    Activity的优先级</p>
<ul>
<li><p>处于前台的Activity优先级最高</p>
</li>
<li><p>可见但非前台的Activity优先级次之，如当前开启一个对话框，Activity仍可见</p>
</li>
<li><p>后台Activity最低,已经被暂停了</p>
<h4 id="3-生命周期图"><a href="#3-生命周期图" class="headerlink" title="3. 生命周期图"></a>3. 生命周期图</h4></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">graph TB</span><br><span class="line">     subgraph right</span><br><span class="line">        startRight(Activity) --&gt; create[onCreate] --&gt; onRestoreInstanceState</span><br><span class="line">    end</span><br><span class="line">    subgraph left</span><br><span class="line">        startLeft(Activity) --&gt; onSaveInstanceState --&gt; onDestory</span><br><span class="line">        onSaveInstanceState -- 重新创建 --&gt; create</span><br><span class="line">    end</span><br><span class="line">   </span><br></pre></td></tr></table></figure>



<p>Android系统在这个过程中自动为我们进行了一些数据的恢复，主要通过View的onRestoreInstanceState和onSaveInstanceState方法进行，其流程如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">graph TB</span><br><span class="line">Activity --委托--&gt; window --委托--&gt; 顶层view --将保存数据以及恢复数据方法进行分发式调用--&gt;各个view</span><br></pre></td></tr></table></figure>

<h4 id="4-阻止因状态配置变化重新创建Activity"><a href="#4-阻止因状态配置变化重新创建Activity" class="headerlink" title="4. 阻止因状态配置变化重新创建Activity"></a>4. 阻止因状态配置变化重新创建Activity</h4><p>在AndroidManifest中配置configChanges属性，最常用的值为locale、orientation、keyboardHidden三个选项，分别为切换系统语言、横竖屏切换以及用户调出了键盘，多个值可用|间隔，当设置横竖屏切换时还有加上screenSize选项，因为屏幕大小也会变</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;activity android:name&#x3D;&quot;.MainActivity&quot;</span><br><span class="line">          android:configChanges&#x3D;&quot;orientation | screenSize&quot;&gt;</span><br><span class="line">          &lt;intent-filter&gt;</span><br><span class="line">              &lt;action android:name&#x3D;&quot;android.intent.action.MAIN&quot; &#x2F;&gt;</span><br><span class="line"></span><br><span class="line">              &lt;category android:name&#x3D;&quot;android.intent.category.LAUNCHER&quot; &#x2F;&gt;</span><br><span class="line">          &lt;&#x2F;intent-filter&gt;</span><br><span class="line">      &lt;&#x2F;activity&gt;</span><br></pre></td></tr></table></figure>

<p>重写onConfigurationChanged方法打印成功，其中有个小插曲，抛出<strong>android.util.SuperNotCalledException</strong>，原因是没有调用父类的方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">super</span>.onConfigurationChanged(newConfig);</span><br></pre></td></tr></table></figure>



<p><img src="C:\Users\xxc、\AppData\Roaming\Typora\typora-user-images\image-20200118180613221.png" alt="image-20200118180613221"></p>
<h3 id="三、-Activity启动模式"><a href="#三、-Activity启动模式" class="headerlink" title="三、 Activity启动模式"></a>三、 Activity启动模式</h3><p>​    主要分为standard、singleTop、singleTask、singleInstance几个方法</p>
<pre><code>#### 1. standard 标准模式</code></pre>
<p>​    系统默认的模式，每创建一个Activity都会将Activity放入<strong>默认的Activity栈</strong>中，当销毁一个Activity时将其栈顶元素栈中推出。当我们使用ApplicationContext去创建Activity会抛异常，因为ApplicationContext不知道默认的Activity栈，我们可以使用FLAG_ACTIVITY_NEW_TASK去打开，但这已经不是standard模式启动了</p>
<h4 id="2-singleTop"><a href="#2-singleTop" class="headerlink" title="2. singleTop"></a>2. singleTop</h4><p>​    在这种情况下如果新的Activity已经位于栈顶则复用Activity，其onNewIntent方法会被调用</p>
<h4 id="3-singleTask"><a href="#3-singleTask" class="headerlink" title="3. singleTask"></a>3. singleTask</h4><p>​    栈内复用，当栈中有该Activity就不会创建新的Activity，将该Activity提至栈顶，并调用onNewIntent方法</p>
<h4 id="4-singleInstance"><a href="#4-singleInstance" class="headerlink" title="4. singleInstance"></a>4. singleInstance</h4><p>​    加强版singleTask，该Acitivity会单独存在一个Activity中，除非该任务栈被销毁，否则一直不会创建新的Activity</p>
<h4 id="5-任务栈的配置"><a href="#5-任务栈的配置" class="headerlink" title="5. 任务栈的配置"></a>5. 任务栈的配置</h4><p>​    我们可以通过taskAffinity进行配置任务栈，默认情况下是应用的包名也就是默认任务栈</p>
<h4 id="6-Activity的flags"><a href="#6-Activity的flags" class="headerlink" title="6. Activity的flags"></a>6. Activity的flags</h4><ul>
<li>（<strong>常用</strong>）FLAG_ACTIVITY_NEW_TASK 这个标志位为指定singleTask方式启动 </li>
<li>FLAG_ACTIVITY_SINGLE_TOP 指定singleTop方式启动</li>
<li>FLAG_ACTIVITY_CLEAR_TOP 位于他上面的Activity都会出栈</li>
<li>FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 具有这个标记的Activity不会出现在历史记录中</li>
</ul>
<h3 id="四、-IntentFilter的匹配规则"><a href="#四、-IntentFilter的匹配规则" class="headerlink" title="四、 IntentFilter的匹配规则"></a>四、 IntentFilter的匹配规则</h3><p>Activity显示调用需要包名和类名，其中包名通过context获取，故我们不需直接给出包名，如下即可</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">startActivity(new Intent(this,MainActivity.class));</span><br></pre></td></tr></table></figure>





<p>Activity隐式调用需要在Activity标签下配置intent-filter标签，其有action、category、data等过滤信息，为了匹配过滤列表，需要同时匹配三者，<strong>注意intent-filter可以配置多个</strong>，intent只要能匹配一组intent-filter即可,其中每个intent-filter必须包括android.intent.category.DEFAULT</p>
<h4 id="1-action匹配规则"><a href="#1-action匹配规则" class="headerlink" title="1. action匹配规则"></a>1. action匹配规则</h4><p>​    action是一个字符串，系统预定义了一些字符串，我们也可以自定义，action的匹配规则是必须能够和过滤规则中的action一致，一个intent-filter可以有多个action，那么只需要与其中一个匹配即可</p>
<h4 id="2-category匹配规则"><a href="#2-category匹配规则" class="headerlink" title="2. category匹配规则"></a>2. category匹配规则</h4><p>​    系统预定义了一些category，我们也可以自定category，category需要intent中的所有category都在同一个intent-filter中定义，都能从中找到即可匹配，当然intent可以不给category。<strong>注意：intent-filter必须配置一个android.intent.category.DEFAULTandroid.intent.category.DEFAULT</strong></p>
<h4 id="3-data匹配规则"><a href="#3-data匹配规则" class="headerlink" title="3. data匹配规则"></a>3. data匹配规则</h4><p>​    data的规则和action类似，如果过滤规则中定义了data，那么intent中也要定义匹配的data,data的格式：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;data</span><br><span class="line">                   android:scheme&#x3D;&quot;string&quot;</span><br><span class="line">                   android:host&#x3D;&quot;string&quot;</span><br><span class="line">                   android:port&#x3D;&quot;8080&quot;</span><br><span class="line">                   android:path&#x3D;&quot;&#x2F;&quot;</span><br><span class="line">                   android:pathPattern&#x3D;&quot;string&quot;</span><br><span class="line">                   android:pathPrefix&#x3D;&quot;&#x2F;&quot;</span><br><span class="line">                   android:mimeType&#x3D;&quot;string&quot;&gt;&lt;&#x2F;data&gt;</span><br></pre></td></tr></table></figure>

<p>​    data 的结构(各部分都需要满足格式要求)</p>
<p>​    data分为URI和mimetype两部分，其中mimetype表示媒体类型，URI表示路径</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;scheme&gt;:<span class="comment">//&lt;host&gt;:&lt;port&gt;/[path]|[pathPrefix]|[pathPattern]</span></span><br></pre></td></tr></table></figure>

<p>​    其中path、pathPrefix、pathPattern表示路径、路径前缀、路径格式(可以包含通配符)</p>
<h4 id="4-避免Activity隐式跳转失败"><a href="#4-避免Activity隐式跳转失败" class="headerlink" title="4. 避免Activity隐式跳转失败"></a>4. 避免Activity隐式跳转失败</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 通过PackageManager进行查询是否匹配</span><br><span class="line">getPackageManager().resolveActivity(intent,PackageManager.MATCH_DEFAULT_ONLY);</span><br><span class="line">getPackageManager().queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY)</span><br></pre></td></tr></table></figure>










      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/08/07/android/Activity%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%8E%A2%E7%B4%A2/" data-id="ckdkdagt40000voutbbkpdqui" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="./page/3/">&amp;laquo; Prev</a><a class="page-number" href="./">1</a><a class="page-number" href="./page/2/">2</a><a class="page-number" href="./page/3/">3</a><span class="page-number current">4</span>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="./archives/2020/08/">August 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="./2020/08/07/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B9%8B%E9%93%BE%E8%A1%A8/">(no title)</a>
          </li>
        
          <li>
            <a href="./2020/08/07/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B9%8B%E6%A0%88%E4%B8%8E%E9%98%9F%E5%88%97/">(no title)</a>
          </li>
        
          <li>
            <a href="./2020/08/07/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B9%8B%E6%95%B0%E7%BB%84/">(no title)</a>
          </li>
        
          <li>
            <a href="./2020/08/07/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E6%80%9D%E7%BB%B4%E5%AF%BC%E5%9B%BE/">(no title)</a>
          </li>
        
          <li>
            <a href="./2020/08/07/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/SpringBoot%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">(no title)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 xiaxuchen<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="./" class="mobile-nav-link">Home</a>
  
    <a href="./archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="./fancybox/jquery.fancybox.css">

  
<script src="./fancybox/jquery.fancybox.pack.js"></script>




<script src="./js/script.js"></script>




  </div>
</body>
</html>